package com.jerry.alibaba.transaction.controller;

import com.jerry.alibaba.transaction.entity.CommonResult;
import com.jerry.alibaba.transaction.entity.Order;
import com.jerry.alibaba.transaction.service.OrderServcie;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class OrderController {

    @Resource
    private OrderServcie orderService;

    @PostMapping(value="/order/create")
    public CommonResult create(@RequestBody Order order) {
        orderService.create(order);
        return new CommonResult(200, "订单创建成功");
    }

    @GetMapping(value="/order/get/{id}")
    public CommonResult getById(@PathVariable("id") Long id) {
        Order order = orderService.getById(id);
        if (order != null) {
            return new CommonResult(200, "查询成功", order);
        } else {
            return new CommonResult(444, "查询失败，查询id="+id, null);
        }
    }

    @GetMapping(value="/order/get")
    public CommonResult getList() {
        List<Order> orderList = orderService.getList();
        if (orderList != null) {
            return new CommonResult(200, "查询成功", orderList);
        } else {
            return new CommonResult(444, "查询失败", null);
        }
    }

}
